﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Xml;
using DoubanApiLib.Base;

namespace DoubanApiLib.Access
{
    public class AccessBase
    {
        /// <summary>
        /// 调用API获取DataSet
        /// </summary>
        /// <param name="apiUrl"></param>
        /// <returns></returns>
        public static DataSet GetApiDataSet(string apiUrl)
        {
            XmlDocument document = new XmlDocument();
            document.LoadXml(HttpHelper.SendRequestWithNoData(apiUrl));
            DataSet ds = new DataSet();
            ds.ReadXml(new XmlNodeReader(document));
            return ds;
        }

        /// <summary>
        /// 调用API获取DataSet (需要授权信息)
        /// </summary>
        /// <param name="apiUrl"></param>
        /// <returns></returns>
        public static DataSet GetApiDataSet(string apiUrl,string accessToken, string accessTokenSecret)
        {

            string oauthheader = Until.CreateOauthHeader(apiUrl, accessToken, accessTokenSecret);
            XmlDocument document = new XmlDocument();
            document.LoadXml(HttpHelper.SendRequestWithNoData(apiUrl,oauthheader));
            DataSet ds = new DataSet();
            ds.ReadXml(new XmlNodeReader(document));
            return ds;
        }
    }
}
